#include "SEGTask.h"

uint8_t SEGCode[10]={0x77,0x41,0xB3,0xB6,0xD4,0xE6,0xE7,0x34,0xF7,0xF6};
uint8_t Number[6]={};
uint8_t LatchBitCode[6]={0x20,0x10,0x08,0x04,0x02,0x01};


void SEG7delay(unsigned int DelayT)
{
	unsigned int i;
	for(i=0;i<DelayT;i++);
}


void SEG_Latch(void)	// 数码管段位锁存
{
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, 1);
	HAL_GPIO_WritePin(GPIOB, GPIO_PIN_15, 0);
}

void BIT_Latch(void)	// 数码管位锁存
{
	HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, 1);
	HAL_GPIO_WritePin(GPIOG, GPIO_PIN_6, 0);
}

void Set_GPIOCdata0_7(uint8_t i)
{
	uint32_t data;
	data=GPIOC->ODR;
	data&=0xFF00;
	data|=i;
	GPIOC->ODR = data;
}

void DisplayLED7R(uint16_t VoltValue)	//display Voltage on the Right 3 LED7
{
	uint8_t temp;
	uint8_t tt=0;

	Number[2]=VoltValue/100;
	Number[1]=(VoltValue-Number[2]*100)/10;
	Number[0]=VoltValue % 10;

	while(1)
	{
	tt=0;
	for(tt=0; tt<3; tt++)
	{
		temp=SEGCode[Number[tt]];
		if (tt==2)
			temp = temp | 0x08;

		Set_GPIOCdata0_7(LatchBitCode[tt]);
		BIT_Latch();
		Set_GPIOCdata0_7(temp);
		SEG_Latch();

	}
	}
}

//END of SEG7

